import Vue from 'vue'
import App from './App.vue'
import "./assets/css/index.scss" //加载初始化样式
import 'element-ui/lib/theme-chalk/index.css'
import router from './router'
import ElementUI from 'element-ui';
import EVueContextmenu from 'e-vue-contextmenu'

import JsonExcel from 'vue-json-excel'
Vue.component('downloadExcel', JsonExcel)


Vue.config.productionTip = false
Vue.use(ElementUI);
Vue.use(EVueContextmenu)
Vue.filter('timeChange', (value) => {
  let date = new Date(value);//如果date为13位不需要乘1000
  let Y = date.getFullYear() + '-';
  let M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
  let D = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate()) + ' ';
  let h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
  let m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
  let s = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
  return value ? Y + M + D + h + m + s : '';
})
Vue.prototype.$meInfo = {};
//权限检测
Vue.prototype.$checkRoles = function (arrays) {
  if (this.$meInfo && this.$meInfo.auths)
    if (this.$meInfo.isAdmin)
      return true
    else
      for (let i = 0; i < arrays.length; i++) {
        if (this.$meInfo.auths.indexOf(arrays[i]) === -1)
          return false
      }
  else return false
  return true
};

router.afterEach((to, from) => {
  /** 解决页面刷新数据丢失问题 **/
  if (sessionStorage.pageStore) {
    let pageStore = JSON.parse(sessionStorage.pageStore);
    if (pageStore.name === to.name) {
      Object.assign(to.params, pageStore.params);
    }
  }
});

new Vue({
  el: '#app',
  router,
  components: {App},
  template: '<App/>'
})
